package com.lap.context.starter.entity;

import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户信息
 *
 * @author Shuisheng Lao(劳水生)
 * @version 1.0.0
 */
@Data
@Slf4j
public class UserInfo implements ContextDefinition {

  private Integer userId;
  private String username;
  private String fullName;

  @Getter(AccessLevel.NONE)
  private Map<String, String> map;

  @Override
  public Integer getInteger(String key) {
    if (MapUtils.isNotEmpty(map)) {
      String valueString = map.get(key);

      try {
        return Integer.valueOf(valueString);
      } catch (NumberFormatException e) {
        log.warn("UserInfo number format is error:{}", key);
      }
    }
    return -1;
  }

  @Override
  public String getString(String key) {
    return MapUtils.isNotEmpty(map) ? map.get(key) : "";
  }
}
